TARGET = target/riscv64gc-unknown-none-elf/debug
DEBUG = /home/ych/riscv64-unknown-elf-gcc-8.3.0-2020.04.1-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gdb
QEMU = qemu-system-riscv64
run:cut
	$(QEMU) \
    -machine virt \
    -nographic \
    -bios ../bootloader/rustsbi-qemu.bin \
    -device loader,file=$(TARGET)/os.bin,addr=0x80200000 \
  
qemu:cut
	$(QEMU) \
    -machine virt \
    -bios ../bootloader/rustsbi-qemu.bin \
    -device loader,file=$(TARGET)/os.bin,addr=0x80200000 \
    -s -S

cut:build
	rust-objcopy --strip-all $(TARGET)/os -O binary $(TARGET)/os.bin

debug:
	$(DEBUG) \
    -ex 'file $(TARGET)/os' \
    -ex 'set arch riscv:rv64' \
    -ex 'target remote localhost:1234'

build:
	cargo build    
